package com.lagou;

import com.lagou.service.UserServiceImpl;
import com.lagou.zk.MyZkClient;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

@SpringBootApplication(scanBasePackages = "com.lagou")
public class ServerBoot implements ApplicationContextAware {

    private static ApplicationContext context;

    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(ServerBoot.class, args);
        String ip="127.0.0.1";
        int port=8999;
        MyZkClient myZkClient = (MyZkClient)context.getBean("MyZkClient");
        myZkClient.setIp(ip);
        myZkClient.setPort(port);
        myZkClient.initialize();
        //启动服务器
        UserServiceImpl.startServer("127.0.0.1",8999);
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context=applicationContext;
    }
}
